package com.future.common.security.config;

import com.future.common.security.handler.RtErrorHandler;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

/**
 * @ClassName : StatusResourceServerAutoConfig
 * @Author : lby
 * @Date: 2021/5/6 21:05
 * @Description : 全局资源注入
 */
@ComponentScan("com.future.common.security")
public class StatusResourceServerAutoConfig {
    @Bean
    @Primary
    @LoadBalanced
    public RestTemplate lbRestTemplate() {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setOutputStreaming(false);
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        restTemplate.setErrorHandler(new RtErrorHandler());

        return restTemplate;
    }
}
